package com.roger.cmdkit.cases;

import com.roger.cmdkit.base.CmdBase;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import static com.roger.cmdkit.base.CmdHelper.getNextArg;

public class TestCmd implements CmdBase {
    private Process process;
    @Override
    public void cmdS(String[] args) {
        try {
            String testType= getNextArg(args,"--test-cmd");
            String testTimes= getNextArg(args,"-n");
            Runtime runtime = Runtime.getRuntime();
            process = runtime.exec(testType);
            BufferedReader br = new BufferedReader(new InputStreamReader(process.getInputStream(), "UTF-8"));
            String line;
            while ((line = br.readLine()) != null) {
                System.out.println(line);
            }
            process.waitFor();
            br.close();
            process.destroy();
            if(!testTimes.equals("")) System.out.println(testTimes);
        }catch (Throwable e){
            process.destroy();
            System.out.println("wtk.exe: ---test-wifi requires an right id");
        }

    }
}
